<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>浙江在线预约诊疗服务平台</title>
    <link rel="stylesheet" href="public/css/lib/bootstrap.min.css" tppabs="https://guahao.zjol.com.cn/public/css/lib/bootstrap.min.css">
    <link rel="stylesheet" href="public/css/lib/glider.min.css" tppabs="https://guahao.zjol.com.cn/public/css/lib/glider.min.css">
    <link rel="stylesheet" href="public/css/lib/bootstrap-datepicker.min.css" tppabs="https://guahao.zjol.com.cn/public/css/lib/bootstrap-datepicker.min.css">
    <link rel="stylesheet" href="public/css/lib/jquery-confirm.min.css" tppabs="https://guahao.zjol.com.cn/public/css/lib/jquery-confirm.min.css">

    <!-- <link rel="stylesheet" href="/public/css/lib/material-icons.css">
    <link rel="stylesheet" href="/public/css/lib/bootstrap-material-design.min.css" > -->

    <link rel="stylesheet" href="public/css/global.css" tppabs="https://guahao.zjol.com.cn/public/css/global.css">


    <link rel="stylesheet" href="public/css/forget_pwd.css" tppabs="https://guahao.zjol.com.cn/public/css/forget_pwd.css">

</head>

<body>

<div class="topbar">
    <div class="topbar-container row">
        <div class="col-6 topbar-user-info">
            <a href="login.html" tppabs="https://guahao.zjol.com.cn/login">返回</a>
        </div>
    </div>
</div>
</div>


<div class="main-container" style="padding-bottom: 40px;">
    <div class="forget-pwd-content">

        <div class="step-wrap" id="step1">
            <div class="step-title">绑定手机</div>
            <div class="forget-pwd-item">
                <div class="forget-pwd-item-name">手机号</div>
                <div class="forget-pwd-item-ipt">
                    <input type="text" class="form-control username-ipt" placeholder="请输入手机号" id="userphone">
                    <span class="login-ntf name" id="userphone2"></span>
                </div>
            </div>

            <div class="forget-pwd-item">
                <div class="forget-pwd-item-name">验证码</div>
                <div class="forget-pwd-item-ipt clearfix">
                    <div class="float-left" style="width: 60%;">
                        <input type="text" class="form-control verify-ipt" placeholder="请输入验证码" id="captcha">
                        <span class="login-ntf name" id="captcha2"></span>
                    </div>
                    <div class="float-left" style="width: 40%; padding-left: 30px;">
                        <button  class="btn btn-success btn-block" id="verfycode">获取验证码</button>
                    </div>
                </div>
            </div>

            <div style="margin-top: 20px;">
                <button class="btn btn-success btn-block" id="submitCode" >确定</button>
            </div>

        </div>
    </div>
</div>


</body>

</html>
<script src="../page/public/js/lib/jquery.js"></script>
<script>
    $(function(){
        var category=window.location.search;
        var wxtoken=category.substring(category.lastIndexOf("=")+1,category.length);
        $("#submitCode").click(function(){
            $("#userphone2").html("");
            $("#captcha2").html("");
            var phone =$("#userphone").val();
            var sms=$("#captcha").val();
            if((/^1\d{10}$/.test(phone))) {
                /*  if((/^\d{4}$/.test(captcha))) {*/
                $.ajax({
                    type: "post",
                    url: "/hospital/api/user/binding/login/sms",
                    data: {
                        /*"sms":captcha,*/
                        "phone": phone
                    },
                    dataType: "json",
                    success: function (data) {
                        console.log(data);
                        if(data.code==1){
                            alert(data.msg);
                        }
                        if(data.code==0){
                            getlogin();
                        }
                    }
                })
                /* }else{
                     $("#captcha2").append("验证码必须为4位数")
                 }*/
            }else{
                $("#userphone2").append("手机格式不正确")
            }
            function getlogin() {
                $.ajax({
                    type: "GET",
                    url: "/hospital/api/user/login/wetoken",
                    data: {"wxtoken": wxtoken, "phone": phone},
                    dataType: "json",
                    success: function (data, textStatus, request) {
                        console.log(data);
                        if (data.code == 0) {
                            alert(data.msg)
                            localStorage.setItem("token", request.getResponseHeader("token"));
                            location.href = "home.html"
                        }
                        if (data.code == 1) {
                            alert(data.msg)
                        }
                    }
                })

            }
        })

        $("#verfycode").click(function(){
            var phone=$("#userphone").val();
            $("#userphone2").html("");
            var codeType=2;
            $.ajax({
                type: "post",
                url: "/hospital/api/sms/verfycode",
                data: {
                    "codeType":codeType,
                    "phone": phone
                },
                dataType: "json",
                success: function (data) {
                    console.log(data);
                    if(data.code==200001){
                        $("#userphone2").append(data.msg);
                    }

                }
            })
        })


    })
</script>